package com.upcode.weighing.util.ops;

import cn.hutool.core.io.FileUtil;
import java.io.File;
import java.io.IOException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Base64;
import java.util.List;

public class OtherUtills {

    //private static final String path="D:\\aaa.txt";//本地
    //private static final String path="/dr/error.txt";//公司
    private static final String path="/ny_data/FileServDir/dr/error.txt";//客户

    /**
     * 创建txt写入list
     * @param list
     * @throws IOException
     */
    public static void path(List list) throws IOException {
        File file=new File(path);
        File parentFile = file.getParentFile();
        if(!parentFile.exists()){
            parentFile.mkdirs();
        }
        if(file.exists()){
            file.delete();
        }
        file.createNewFile();
        File f= FileUtil.writeUtf8Lines(list,file);
    }

    public static void delPath(){
        File f=new File(path);
        if(f.exists()){
            f.delete();
        }
    }

    public static boolean checkStr(String s){
        if(s != null && s.trim().length() != 0){
            return true;
        }
        return false;
    }

    public static boolean checkContains(String str1,String str2){
        if(str1.contains(str2)){
            return true;
        }
        return false;
    }

    public static String removeSpeace(String str){
        return str.trim();
    }

    public static String encode(String str){
        String res="";
        try{
            res=URLEncoder.encode(str,"UTF-8");
        }catch (Exception e){
            e.printStackTrace();
        }
        return res;
    }

    public static String decode(String str){
        String res="";
        try{
            res= URLDecoder.decode(str,"UTF-8");
        }catch (Exception e){
            e.printStackTrace();
        }
        return res;
    }

    public static String base64Encoder(String str){
        String res="";
        try{
            res= Base64.getEncoder().encodeToString(str.getBytes("UTF-8"));
        }catch (Exception e){
            res=str;
            e.printStackTrace();
        }
        return res;
    }

    public static String base64Decoder(String str){
        return new String(Base64.getDecoder().decode(str));
    }

}
